package org.ljy.springblog.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.ljy.springblog.model.BlogInfo;

import java.util.List;

@Mapper
public interface BlogInfoMapper {

    //1.查询所有的博客内容
    @Select("select id,title,content,user_id,update_time from `blog` where delete_flag=0 order by id desc")
    List<BlogInfo> selectAllBlogInfo();

    //2.根据博客ID，查询博客信息
    @Select("select id,title,content,user_id,update_time from `blog` where delete_flag=0 and id=#{id}")
    BlogInfo selectBlogInfoById(Integer id);

    //3.插入博客
    @Insert("insert into `blog` (title,content,user_id) values (#{title},#{content},#{userId})")
    Integer insertBlogInfo(BlogInfo blogInfo);

    //4.更新博客
    Integer updateBlogInfo(BlogInfo blogInfo);

    //5.删除博客
    @Update("update `blog` set delete_flag=1 where id=#{id}")
    Integer updateBlogInfoById(BlogInfo blogInfo);

}
